---@class Battle.PlayerSystem
local PlayerSystem = Battle.CreateClass("PlayerSystem")
Battle.PlayerSystem = PlayerSystem
local this = PlayerSystem


function PlayerSystem.OnCreate()
    ---@type Battle.PlayerRobot[]
    this.players = {}
    Battle.ClientBattle:RegisterUpdateCallback(this.Update)
end
function PlayerSystem.OnDestroy()

end
function PlayerSystem.CreatePlayer(id,camp,cards)
    ---@type Battle.PlayerRobot
    local robot
    if camp == Battle.CampType.Blue then
        robot = Battle.BluePlayer.New()
    else
        robot = Battle.RedPlayer.New()
    end
    robot:Init(id,camp,cards)
    this.players[camp] = robot
end
function PlayerSystem.SetCardList(cards,enemyCards)
    this.CreatePlayer(1,Battle.CampType.Blue,cards)
    this.CreatePlayer(2,Battle.CampType.Red,enemyCards)
end
function PlayerSystem.OnInitialize()
    for k,v in pairs(this.players) do
        v:OnInitialize()
    end
end

function PlayerSystem.Update(dt)
    for k,v in pairs(this.players) do
        v:Update(dt)
    end
end
function PlayerSystem.CreateLord()
    local mPos = Battle.SceneMgr.myBornPos
    local mForward = Battle.SceneMgr.myBornForward
    local ePos = Battle.SceneMgr.enemyBornPos
    local eForward = Battle.SceneMgr.enemyBornForward

    Battle.EntityFactory.CreateLord(101,Battle.CampType.Blue,mPos.x,0,mPos.z,mForward.x,mForward.y,mForward.z)
    local lord = Battle.EntityFactory.CreateLord(102,Battle.CampType.Red,ePos.x,0,ePos.z,eForward.x,eForward.y,eForward.z)
    lord.aiSystem:AddAi(lord,Battle.AiType.EnemyLordAi)
end


function PlayerSystem.AccelerateAllPlayer(energyRecover)
    for k,v in pairs(this.players) do
        v:ChangeEnergyRecover(energyRecover)
    end
end
function PlayerSystem.GetPlayer(camp)
    return this.players[camp]
end
---@return Battle.BluePlayer
function PlayerSystem.GetMyPlayer()
    return this.players[Battle.CampType.Blue]
end
